//
//  rootViewController.m
//  NXLib
//
//  Created by AK on 14-3-7.
//  Copyright (c) 2014年 AK. All rights reserved.
//

#import "rootViewController.h"
#import "NXLineLabel.h"
#import "NXMultLabel.h"
#import "StudyBlocks.h"
#import "UISlider+UISliderBackImage.h"
#import "Cat.h"
#import "bolo_SingleDemo.h"

#import "NXlib.h"

#import "Appirater.h"

#import "NXAppReview.h"

#import "NXAudioQueuePlayAudio.h"



/*
 
 Test Mode:
 带下划线的label                  0
 不同字号 颜色的label              1
 block GCD的DEMO                 2
 
 
 */

extern NSString *CTSettingCopyMyPhoneNumber();

#define TestMode        2

@interface rootViewController ()<UITableViewDataSource,UITableViewDelegate>
{

    NSMutableArray * rootTableDataArray;
}

@end

@implementation rootViewController

@synthesize name;

//私有 api
-(NSString *)myNumber
{
	return CTSettingCopyMyPhoneNumber();
}

- (id)init
{
    if (self = [super init])
    {
  
		//本机手机号
		NSLog(@"本机手机号 %@",[[NSUserDefaults standardUserDefaults] objectForKey:@"SBFormattedPhoneNumber"]);
        NSLog(@"selfC %@",self.name);
		
		//播放声音
//		NXAudioQueuePlayAudio * player = [[NXAudioQueuePlayAudio alloc] initWithAudio:[[NSBundle mainBundle] pathForResource:@"music_logo"ofType:@"wav"]];
//		[player description];
		
		// 前面不成立时会提示
		NSAssert(3==3, @"asdfasdfasd");
  
	     	NSString *lan=[[[NSUserDefaults standardUserDefaults]objectForKey:@"AppleLanguages"] objectAtIndex:0];

		NSLog(@"lalalalalal %@",lan);
        /**
         *  二分法 DEMO
         */
        NSMutableArray *arr = [[NSMutableArray alloc] initWithObjects:@"1.",@"2.",@"3.",@"4.",@"5.",@"6.",@"7.",@"8.", nil];
		
		float  tempf = 2.1;
		
		[arr addObject:[NSString stringWithFormat:@"%f",tempf]];
		
		NSLog(@"asdfasdfalkqjwelrf %@",arr.description);
	
		int leftIndex = 0;
		int rightInDex = (int)arr.count;
		
		float currFloat = 0.;
		float nextFloat = 0.;
		
 		while (leftIndex <= rightInDex)
		{
			int midIndex = (leftIndex + rightInDex)/2;
			
			if(((NSString *)[arr objectAtIndex:midIndex]).floatValue < tempf)
			{
				leftIndex = midIndex +1;
				
			}
			else if(((NSString *)[arr objectAtIndex:midIndex]).floatValue  > tempf)
			{
				rightInDex = midIndex - 1;
				
			}
			else
			{
				NSLog(@"你要找的就是当前时间 %f",((NSString *)[arr objectAtIndex:midIndex]).floatValue);
				
				if (arr.count == 2)
				{
//					currListSet = nextListSet = (bolo_LiveListModel *)[allListArray objectAtIndex:midIndex];
				}
				else
				{
					
					currFloat = ((NSString *)[arr objectAtIndex:midIndex-1]).floatValue;
					
					nextFloat = ((NSString *)[arr objectAtIndex:midIndex+1]).floatValue;
				 
					NSLog(@"currFloat %f,,,nextfloat %f",currFloat,nextFloat);
					
//					break;
				}
				
				
			}
			
		}
 
    }
    
    return self;
}

 
- (void)viewDidLoad
{
    [super viewDidLoad];
	
	self.title = @"NXlib BOX";
 
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
    UISlider * sliderA = [[UISlider alloc]initWithFrame:CGRectMake(30, 320, 257, 7)];
    sliderA.backgroundColor = [UIColor clearColor];
    sliderA.value = 1.0;
    sliderA.minimumValue = 0.7;
    sliderA.maximumValue = 1.0;

    [sliderA setTrackImageAndThumbImage:[UIImage imageNamed:@"33333.png"] minimumTrackImage:[UIImage imageNamed:@"22222.png"] maximumTrackImage:[UIImage imageNamed:@"11111.png"]];
    [self.view addSubview:sliderA];
    
    [[bolo_SingleDemo singleDemo] say];
    
#if (TestMode == 0)
    
    NXLineLabel * lineLabel = [[NXLineLabel alloc] initWithFrame:CGRectMake(10, 100, 100, 20)];
    lineLabel.text = @"这是一个有下划线的";
    [lineLabel setBackgroundColor:[UIColor clearColor]];
    [lineLabel setTextColor:[UIColor blackColor]];
    lineLabel.lineType = LineTypeDown;
    [self.view addSubview:lineLabel];
 
#elif (TestMode == 1)
    
    NSMutableArray * setArray_f = [[NSMutableArray alloc] initWithCapacity:5];
    [setArray_f addObject:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor],@"Color",[UIFont systemFontOfSize:14],@"Font",nil]];
    
    [setArray_f addObject:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blueColor],@"Color",[UIFont systemFontOfSize:14],@"Font",nil]];
    
    NXMultLabel * showLable = [[NXMultLabel alloc] initWithFrame:CGRectMake(10,130,320,30)];
    showLable.alignmentType = Muti_Alignment_Mid_Type;
    //    [showLable setBackgroundColor:[UIColor yellowColor]];
    [showLable setShowText:@"你申请的账号:|1007" Setting:setArray_f];
    [self.view addSubview:showLable];
    [showLable release];
    
#elif (TestMode == 2)
    
    StudyBlocks * sb = [[StudyBlocks alloc] init];
    [sb description];
    
#endif
    
//面向对象特点 封装 继承 多态
    Animal * ddd = [[Cat alloc] init];
    //over read
    [ddd call];
    //over load ??
    NSLog(@"%d",[ddd calculateByWidth:100 andXxxHeight:10]);
    ;
    
    //多态，父类指针指向子类对象
    [ddd sleep];
    
    //add a tableView
    UITableView * rootTableView  = [[UITableView alloc] initWithFrame:CGRectMake(10, 64, 300, 368) style:UITableViewStylePlain];
    rootTableView.delegate = self;
    rootTableView.dataSource = self;
    rootTableView.showsVerticalScrollIndicator = NO;
    rootTableView.separatorColor = [UIColor blackColor];
    [rootTableView setBackgroundColor:[UIColor clearColor]];
    rootTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    [self.view addSubview:rootTableView];
    
    rootTableDataArray = [[NSMutableArray alloc] initWithObjects:@"设备info",@"FTP", @"GUPImage",@"评分",nil];
  
    NSNumber * number = @1;
    NSLog(@"asdfasd %@",number);
    
  
    
    NSLog(@"asdfasdfasd %@",NSStringFromSelector(_cmd));
	


    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return rootTableDataArray.count;
}

/*!
 1-重取出来的cell是有可能已经捆绑过数据或者加过子视图的，所以，
 如果有必要，要清除数据（比如textlabel的text）和remove掉add过的子视图（使用tag）。
 2-这样设计的目的是为了避免频繁的 alloc和delloc cell对象而已,没有多复杂。
 3-设计的关键是实现cell和数据的完全分离
 */
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath :( NSIndexPath*)indexPath
{
    NSString * cellID = @"history777";
	
    UITableViewCell * cell = [[UITableViewCell alloc] init];
  
    NSLog(@"从队列中取出的 cell %@",cell);
    
	if (cell == nil)
	{
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        [cell setSelectionStyle: UITableViewCellSelectionStyleBlue];
        [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
        NSLog(@"new alloc cell");
    }
    NSLog(@"old cell");
    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 100,30)];
    label.text = [rootTableDataArray objectAtIndex:indexPath.row];
    [cell addSubview:label];
  
    return cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row)
	{
		case 0:
		{
			[self deviceInfo];
			
			break;
		}
		case 3:
		{
			[[NXAppReview sharedInstance] rateApp];
			
			break;
		}
			
		default:
		{
			NSLog(@"why is default!!!");
			break;
		}
			
	}
    
}

- (void)deviceInfo
{
	UIDevice * device = [UIDevice currentDevice];
	
	NSLog(@"保存的东西%@",[device newMacAddress]);

}

@end
